home *** CD-ROM | disk | FTP | other *** search
/ Painter Bear's Language Bridge — Italian / Bridge_ponte_itialian.iso / pc / helpers / open.dxr / 00010_high score.ls < prev    next >
Encoding:
Text File  |  2001-02-22  |  7.7 KB  |  217 lines

  1. on compareHighScores
  2.   global gScore, gTopScoreLst
  3.   set timeToUpDAte to 0
  4.   repeat with X = 1 to count(gTopScoreLst)
  5.     if getAt(gTopScoreLst, X) = [] then
  6.       set compareThis to 0
  7.     else
  8.       set compareThis to getAt(getAt(gTopScoreLst, X), 1)
  9.     end if
  10.     if gScore > compareThis then
  11.       set timeToUpDAte to 1
  12.     end if
  13.   end repeat
  14.   return timeToUpDAte
  15. end
  16.  
  17. on Update_High_Score playersInit
  18.   global gScore, gTopScoreLst
  19.   set tempLst to []
  20.   add(tempLst, gScore)
  21.   add(tempLst, playersInit)
  22.   repeat with X = 1 to count(gTopScoreLst)
  23.     if getAt(gTopScoreLst, X) = [] then
  24.       set compareThis to 0
  25.     else
  26.       set compareThis to getAt(getAt(gTopScoreLst, X), 1)
  27.     end if
  28.     if gScore > compareThis then
  29.       addAt(gTopScoreLst, X, tempLst)
  30.       deleteAt(gTopScoreLst, count(gTopScoreLst))
  31.       exit repeat
  32.     end if
  33.   end repeat
  34.   repeat with X = 1 to count(gTopScoreLst)
  35.     set whichScore to getAt(gTopScoreLst, X)
  36.     if whichScore = [] then
  37.       put "0" into line X of field "highscore"
  38.       next repeat
  39.     end if
  40.     put getAt(whichScore, 1) & "," & getAt(whichScore, 2) into line X of field "highscore"
  41.   end repeat
  42. end
  43.  
  44. on saveHighScore
  45.   global gFileDelimiter
  46.   if the machineType = 256 then
  47.     set highFile to getOSDirectory() & gFileDelimiter & "bridge.hsc"
  48.   else
  49.     set highFile to getOSDirectory() & "bridge.hsc"
  50.   end if
  51.   set myFile to new(xtra("FileIO"))
  52.   openFile(myFile, highFile, 2)
  53.   delete(myFile)
  54.   createFile(myFile, highFile)
  55.   openFile(myFile, highFile, 2)
  56.   writeString(myFile, field "highscore")
  57.   closeFile(myFile)
  58. end
  59.  
  60. on nabHighScoreInfo
  61.   global gFileDelimiter
  62.   if the machineType = 256 then
  63.     set highFile to getOSDirectory() & gFileDelimiter & "bridge.hsc"
  64.   else
  65.     set highFile to getOSDirectory() & "bridge.hsc"
  66.   end if
  67.   set myFile to new(xtra("FileIO"))
  68.   openFile(myFile, highFile, 0)
  69.   if status(myFile) < 0 then
  70.     closeFile(myFile)
  71.     createFile(myFile, highFile)
  72.     openFile(myFile, highFile, 0)
  73.   end if
  74.   set theContents to readFile(myFile)
  75.   if getLength(myFile) = 0 then
  76.     writeString(myFile, "4892,cat" & RETURN & "1973,yak" & RETURN & "910,ods" & RETURN & "512,dog" & RETURN & "87,hen")
  77.     put "4892,cat" & RETURN & "1973,yak" & RETURN & "910,ods" & RETURN & "512,dog" & RETURN & "87,hen" into field "highscore"
  78.   else
  79.     put theContents into field "highscore"
  80.   end if
  81.   closeFile(myFile)
  82.   makeTopScoreLst()
  83. end
  84.  
  85. on makeTopScoreLst
  86.   global gTopScoreLst
  87.   set gTopScoreLst to []
  88.   repeat with X = 1 to the number of lines in field "highscore"
  89.     set tempLst to []
  90.     if line X of field "highScore" <> "0" then
  91.       add(tempLst, integer(item 1 of line X of field "highScore"))
  92.       add(tempLst, item 2 of line X of field "highScore")
  93.     end if
  94.     if line X of field "highScore" <> EMPTY then
  95.       add(gTopScoreLst, tempLst)
  96.     end if
  97.   end repeat
  98. end
  99.  
  100. on enterInit whichBtn
  101.   set whichLetter to the name of member the memberNum of sprite whichBtn of castLib "score"
  102.   set whichLetter to chars(word 1 of whichLetter, the number of chars in word 1 of whichLetter, the number of chars in word 1 of whichLetter)
  103.   putInInit(whichLetter)
  104. end
  105.  
  106. on putInInit whichLetter
  107.   global gCurrInit, gThisName, gFstPopInit, gFirstPopLett, gLastPopLett, gFirstPopDelete, gLastPopOk, gfxPath, gFileDelimiter
  108.   if whichLetter = "!" then
  109.     if gThisName <> EMPTY then
  110.       set gCurrInit to gCurrInit - 1
  111.       if gCurrInit = gFstPopInit then
  112.         set gThisName to EMPTY
  113.       else
  114.         set gThisName to chars(gThisName, 1, the number of chars in gThisName - 1)
  115.       end if
  116.       set the member of sprite gCurrInit to member ("entry" & whichLetter) of castLib "score"
  117.       updateStage()
  118.     end if
  119.   else
  120.     if gCurrInit <= (gFstPopInit + 2) then
  121.       set the member of sprite gCurrInit to member ("entry" & whichLetter) of castLib "score"
  122.       updateStage()
  123.       put whichLetter after gThisName
  124.       set gCurrInit to gCurrInit + 1
  125.     end if
  126.   end if
  127.   if gCurrInit >= (gFstPopInit + 3) then
  128.     repeat with X = gFirstPopLett to gLastPopLett
  129.       set whichBtn to the name of member the memberNum of sprite X of castLib "score"
  130.       put "gray" into word the number of words in whichBtn of whichBtn
  131.       set the memberNum of sprite X to the number of member whichBtn
  132.     end repeat
  133.     repeat with X = gFirstPopDelete to gLastPopOk
  134.       set whichBtn to the name of member the memberNum of sprite X of castLib "score"
  135.       put "up" into word the number of words in whichBtn of whichBtn
  136.       set the memberNum of sprite X to the number of member whichBtn
  137.     end repeat
  138.   else
  139.     if gCurrInit = (gFstPopInit + 2) then
  140.       repeat with X = gFirstPopLett to gFirstPopDelete
  141.         set whichBtn to the name of member the memberNum of sprite X of castLib "score"
  142.         put "up" into word the number of words in whichBtn of whichBtn
  143.         set the memberNum of sprite X to the number of member whichBtn
  144.       end repeat
  145.       repeat with X = gFirstPopDelete to gLastPopOk
  146.         set whichBtn to the name of member the memberNum of sprite X of castLib "score"
  147.         put "up" into word the number of words in whichBtn of whichBtn
  148.         set the memberNum of sprite X to the number of member whichBtn
  149.       end repeat
  150.     else
  151.       repeat with X = gFirstPopLett to gFirstPopDelete
  152.         set whichBtn to the name of member the memberNum of sprite X of castLib "score"
  153.         put "up" into word the number of words in whichBtn of whichBtn
  154.         set the memberNum of sprite X to the number of member whichBtn
  155.       end repeat
  156.       if gCurrInit = gFstPopInit then
  157.         set whichBtn to the name of member the memberNum of sprite gFirstPopDelete of castLib "score"
  158.         put "gray" into word the number of words in whichBtn of whichBtn
  159.         set the memberNum of sprite gFirstPopDelete to the number of member whichBtn
  160.       end if
  161.       set whichBtn to the name of member the memberNum of sprite gLastPopOk of castLib "score"
  162.       put "gray" into word the number of words in whichBtn of whichBtn
  163.       set the memberNum of sprite gLastPopOk to the number of member whichBtn
  164.     end if
  165.   end if
  166.   updateStage()
  167. end
  168.  
  169. on prepHighScoreScreen
  170.   global gTopScoreLst, gLine1Init, gLine1Score, gLine2Init, gLine2Score, gLine3Init, gLine3Score, gLine4Init, gLine4Score, gLine5Init, gLine5Score
  171.   repeat with Y = 1 to count(gTopScoreLst)
  172.     case Y of
  173.       "1":
  174.         set whichInit to gLine1Init
  175.         set whichScore to gLine1Score
  176.       "2":
  177.         set whichInit to gLine2Init
  178.         set whichScore to gLine2Score
  179.       "3":
  180.         set whichInit to gLine3Init
  181.         set whichScore to gLine3Score
  182.       "4":
  183.         set whichInit to gLine4Init
  184.         set whichScore to gLine4Score
  185.       "5":
  186.         set whichInit to gLine5Init
  187.         set whichScore to gLine5Score
  188.     end case
  189.     set thisScore to getAt(gTopScoreLst, Y)
  190.     if thisScore <> [] then
  191.       set thisNum to string(getAt(thisScore, 1))
  192.       set thisName to getAt(thisScore, 2)
  193.       updateStage()
  194.       set whichSprite to whichInit
  195.       repeat with X = 1 to the number of chars in thisName
  196.         set whichChar to chars(thisName, X, X)
  197.         set the memberNum of sprite whichSprite to the number of member ("gscore" & whichChar)
  198.         set whichSprite to whichSprite + 1
  199.       end repeat
  200.       updateStage()
  201.       set howManyChars to the number of chars in thisNum
  202.       set whichSprite to whichScore + 6
  203.       repeat with X = the number of chars in thisNum down to 1
  204.         set whichChar to chars(thisNum, X, X)
  205.         set the memberNum of sprite whichSprite to the number of member ("gscore" & whichChar)
  206.         set whichSprite to whichSprite - 1
  207.       end repeat
  208.       next repeat
  209.     end if
  210.     set whichSprite to whichInit
  211.     repeat with X = 1 to 3
  212.       set the memberNum of sprite whichSprite to the number of member "gscore!"
  213.       set whichSprite to whichSprite + 1
  214.     end repeat
  215.   end repeat
  216. end
  217.